﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyHocBongSinhVien.Bus;
using QuanLyHocBongSinhVien.DAO;
using System.Data.SqlClient;


namespace QuanLyHocBongSinhVien
{
    public partial class frmLoaiHocBong : Form
    {
        LoaiHocBong_Bus lhbb = new LoaiHocBong_Bus();
        public frmLoaiHocBong()
        {
            InitializeComponent();
        }

        public bool check_id(string id)
        {

            dbConnection db = new dbConnection();
            SqlParameter mabomon = new SqlParameter("@mahb", id);
            DataTable dt = db.ExecuteQuery("SELECT * FROM LOAIHOCBONG WHERE MAHB = @mahb", mabomon);
            return dt.Rows.Count > 0;
        }
        private void frmLoaiHocBong_Load(object sender, EventArgs e)
        {
            dgvLoaiHocBong.DataSource = lhbb.GetAllLoaiHB();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (check_id(txtMaHB.Text))
            {
                MessageBox.Show("Bạn Đã Nhập Trùng Thông Tin");
                return;
            }

            if (txtMaHB.Text == "")
            {
                MessageBox.Show("Bạn Chưa Nhập Mã");
                return;
            }
            else
            {
                lhbb.Add(txtMaHB.Text,txtTenHB.Text,txtNhaTT.Text,txtGhiChu.Text,int.Parse(txtChiTieu.Text));
                dgvLoaiHocBong.DataSource = lhbb.GetAllLoaiHB();
            }
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            lhbb.Update(txtMaHB.Text, txtTenHB.Text, txtNhaTT.Text, txtGhiChu.Text, int.Parse(txtChiTieu.Text));
            dgvLoaiHocBong.DataSource = lhbb.GetAllLoaiHB();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn xóa bộ môn " + txtMaHB.Text + " không ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                lhbb.Delete(txtMaHB.Text);
                dgvLoaiHocBong.DataSource = lhbb.GetAllLoaiHB();
            }
        }

        private void btnDong_Click(object sender, EventArgs e)
        {

            if (MessageBox.Show("Bạn có muốn thoát không ", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.OK)
            {
                this.Close();
            }

        }

        private void btnLamMoi_Click(object sender, EventArgs e)
        {
            txtMaHB.Clear();
            txtTenHB.Clear();
            txtGhiChu.Clear();
            txtNhaTT.Clear();
            txtChiTieu.Clear();
        }

    }
}
